|
In computer science, a segment tree is a tree data structure for storing intervals, or segments. It allows querying which of the stored segments contain a given point. It is, in principle, a static structure; that is, its structure cannot be modified once it is built. A similar data structure is the interval tree. A segment tree for a set ''I'' of ''n'' intervals uses O(''n'' log ''n'') storage and can be built in O(''n'' log ''n'') time. Segment trees support searching for all the intervals that contain a query point in O(log ''n'' + ''k''), ''k'' being the number of retrieved intervals or segments. Applications of the segment tree are in the areas of computational geometry, and geographic information systems. The segment tree can be generalized to higher dimension spaces as well. ==Structure description== ''This section describes the structure of a segment tree in a one-dimensional space.'' Let ''S'' be a set of intervals, or segments. Let ''p''1, ''p''2, ..., ''pm'' be the list of distinct interval endpoints, sorted from left to right. Consider the partitioning of the real line induced by those points. The regions of this partitioning are called ''elementary intervals''. Thus, the elementary intervals are, from left to right: : That is, the list of elementary intervals consists of open intervals between two consecutive endpoints ''pi'' and ''p''''i''+1, alternated with closed intervals consisting of a single endpoint. Single points are treated themselves as intervals because the answer to a query is not necessarily the same at the interior of an elementary interval and its endpoints. Given a set ''I'' of intervals, or segments, a segment tree ''T'' for ''I'' is structured as follows: * ''T'' is a binary tree. * Its leaves correspond to the elementary intervals induced by the endpoints in ''I'', in an ordered way: the leftmost leaf corresponds to the leftmost interval, and so on. The elementary interval corresponding to a leaf ''v'' is denoted Int(''v''). * The internal nodes of ''T'' correspond to intervals that are the union of elementary intervals: the interval Int(''N'') corresponding to node ''N'' is the union of the intervals corresponding to the leaves of the tree rooted at ''N''. That implies that Int(''N'') is the union of the intervals of its two children. * Each node or leaf ''v'' in ''T'' stores the interval Int(''v'') and a set of intervals, in some data structure. This canonical subset of node ''v'' contains the intervals (''x′'' ) from ''I'' such that (''x′'' ) contains Int(''v'') and does not contain Int(parent(''v'')). That is, each node in ''T'' stores the segments that span through its interval, but do not span through the interval of its parent. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「segment tree」の詳細全文を読む スポンサード リンク
|